Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasi: use WasmMemoryObject handle for perf #43544

Merged
merged 1 commit into from
Jun 25, 2022
Merged

Conversation

devsnek
Copy link
Member

@devsnek devsnek commented Jun 23, 2022

Store WebAssembly.Memory handle as a WasmMemoryObject, which lets us directly grab the ArrayBuffer instead of doing a property lookup in this hot path.

@devsnek devsnek requested a review from cjihrig June 23, 2022 06:21
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/wasi

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jun 23, 2022
@devsnek devsnek force-pushed the use-wasm-memory-object-type branch 3 times, most recently from 0424be9 to 49c3b76 Compare June 23, 2022 06:32
@devsnek devsnek force-pushed the use-wasm-memory-object-type branch 2 times, most recently from d7ead7a to 5a05d10 Compare June 23, 2022 13:53

Local<ArrayBuffer> ab = prop.As<ArrayBuffer>();
std::shared_ptr<BackingStore> backing_store = ab->GetBackingStore();
Local<WasmMemoryObject> memory = PersistentToLocal::Strong(this->memory_);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny and very ignorable style nit:

Suggested change
Local<WasmMemoryObject> memory = PersistentToLocal::Strong(this->memory_);
Local<WasmMemoryObject> memory = PersistentToLocal::Strong(memory_);

More directly, why are we not going on step further and storing the std::shared_ptr<BackingStore> here? That should be even faster.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the arraybuffer gets detached every time the wasm grows its memory. very annoying problem, maybe it will be fixed one day: https://github.com/tc39/proposal-resizablearraybuffer#sync-up-capability-with-webassembly-memorygrow

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@devsnek devsnek force-pushed the use-wasm-memory-object-type branch from c440735 to 98a1262 Compare June 25, 2022 07:03
@nodejs-github-bot
Copy link
Collaborator

PR-URL: #43544
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@devsnek devsnek force-pushed the use-wasm-memory-object-type branch from 98a1262 to 4778831 Compare June 25, 2022 18:01
@devsnek devsnek merged commit d4eef14 into main Jun 25, 2022
@devsnek devsnek deleted the use-wasm-memory-object-type branch June 25, 2022 18:01
devsnek added a commit that referenced this pull request Jun 25, 2022
PR-URL: #43544
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
targos pushed a commit that referenced this pull request Jul 12, 2022
PR-URL: #43544
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
targos pushed a commit that referenced this pull request Jul 20, 2022
PR-URL: #43544
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
targos pushed a commit that referenced this pull request Jul 31, 2022
PR-URL: #43544
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants